<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <FilterTable ref="table" :columns="columns" :dataSource="tableList" :isMemoryPagination="true" :isSelectColumn="false" height="auto" :onColumnsChange="(columns) => (this.columns = columns)">
    </FilterTable>
  </div>
</template>
<script>
import { getflowList, getDealerUser } from '@/api/index.js';
import { getList, gettmFiAccountType, vehicleConfiguration, exporturl, queryOrderLog } from '@/api/dealerSale/OrderManagement/OrderDetailQueryC/index.js';
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
export default {
  data() {
    this.saveData = null;
    return {
      formList: this.createdFrom(),
      columns: this.createdTable(),
      tableList: [],
    };
  },
  components: {},
  props: ['rowData'],
  created() {
    this.init(this.rowData);
    this.queryLog(this.rowData);
  },
  mounted() {
    this.table = this.$refs.table.$refs.pageTable;
  },
  mixins: [dictionary],
  methods: {
    async queryLog(data) {
      const res = await queryOrderLog(data.id);
      this.table.EXECUTE_INSERT(res.data);
    },
    init(data) {
      console.log(data);
      for (let i in data) {
        this.formList.map((x) => {
          if (x.fieldName == i) {
            x.initialValue = data[i];
          }
        });
      }
      // this.formList.find((x) => x.fieldName == 'accountId').initialValue = this.tranfer(data.accountId, data, 1);
      // this.formList.find((x) => x.fieldName == 'addressId').initialValue = this.tranfer(data.addressId, data, 2);
    },
    tranfer(field, data, type) {
      if (type === 1) {
        for (let i in data.accountTypes) {
          if (data.accountTypes[i].accountId === field) {
            return data.accountTypes[i].accountTypeName;
          }
        }
      } else if (type === 2) {
        for (let i in data.addressDtos) {
          if (data.addressDtos[i].addressId === field) {
            return data.addressDtos[i].address;
          }
        }
      }
    },
    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '订单信息',
        },

        {
          type: 'INPUT',
          label: '订单编号',
          fieldName: 'orderNo',
          placeholder: '请输入',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '当前年月',
          fieldName: 'orderYearMonth',
          placeholder: '请输入',
          disabled: true,
          dateType: 'month',
        },
        {
          type: 'SELECT',
          label: '订单状态',
          fieldName: 'mainOrderStatus',
          placeholder: '请选择',
          disabled: true,
          itemList: this.createDictList('2408'),
        },
        {
          type: 'SELECT',
          label: '订单类型',
          fieldName: 'orderType',
          placeholder: '请选择',
          disabled: true,
          itemList: this.createDictList('2410'),
        },
        {
          type: 'SELECT',
          label: '订单明细状态',
          fieldName: 'orderStatus',
          placeholder: '请选择',
          disabled: true,
          itemList: this.createDictList('2415'),
        },
        {
          type: 'INPUT',
          label: '订单经销商',
          fieldName: 'dealerName',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '物料编码',
          fieldName: 'productCode',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '物料描述',
          fieldName: 'productName',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '内饰',
          fieldName: 'trimName',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '销售订单号',
          fieldName: 'doNo',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: 'VIN码',
          fieldName: 'vin',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '外饰',
          fieldName: 'colorName',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '收车地址',
          fieldName: 'address',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '资金类型',
          fieldName: 'accountTypeName',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'SELECT',
          label: '运输方式',
          fieldName: 'transportType',
          disabled: true,
          itemList: this.createDictList('2409'),
        },
        {
          type: 'INPUT',
          label: '市场指导价',
          fieldName: 'sapStandardPrice',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '基础折扣',
          fieldName: 'discountAmount',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '终端奖',
          fieldName: 'sapTerminalBonus',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '优质服务奖',
          fieldName: 'sapServiceBonus',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '促销1',
          fieldName: 'sapPromotionPriceA',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '促销2',
          fieldName: 'sapPromotionPriceB',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '试乘试驾折扣（%）',
          fieldName: 'tryDriveDiscount',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '结算价格',
          fieldName: 'sapSettlementPrice',
          disabled: true,
        },
        {
          type: 'SELECT',
          label: '是否使用返利',
          fieldName: 'isRebate',
          disabled: true,
          itemList: this.createDictList('1004'),
        },
        {
          type: 'INPUT',
          label: '返利使用金额',
          fieldName: 'singleRebateAmount',
          disabled: true,
        },

        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'remark',
          disabled: true,
          selfCols: 2,
        },
        {
          type: 'BREAK_SPACE',
          label: '操作记录',
        },
      ];
    },

    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '单据执行前状态',
          dataIndex: 'fromOrderStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2415'),
          render: (p) => {
            return <span>{this.createDictText(p.row.fromOrderStatus, '2415')}</span>;
          },
        },
        {
          title: '单独执行后状态',
          dataIndex: 'toOrderStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2415'),
          render: (p) => {
            return <span>{this.createDictText(p.row.toOrderStatus, '2415')}</span>;
          },
        },
        {
          title: '操作人员',
          dataIndex: 'createdBy',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '操作时间',
          dataIndex: 'operationDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
        },
        {
          title: '操作类型',
          dataIndex: 'operation',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <span>{p.row.operation}</span>;
          },
        },
        {
          title: '审批意见',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ];
    },
    changeHandle(val) {
      this.saveData = val;
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      }
    },
  },
};
</script>
